package com.tbit.main.util;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件读取
 *
 * @author Leon
 * 2019年1月23日 下午3:57:09
 */
@Slf4j
public class Text {
    /**
     * 读取txt
     */
    public static List<String> readText(String filePath) {
        List<String> result = new ArrayList<String>();
        try {
            String encoding = "UTF-8";
            File file = new File(filePath);
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    result.add(lineTxt);
                }
                read.close();
            } else {
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            log.error(e.getMessage(), e);
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println("test");

    }
}